Passed
Pull Request — master (#165)
by Mathieu
01:54
created

Invoice.getCustomer   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
import {
2
  Entity,
3
  Column,
4
  PrimaryGeneratedColumn,
5
  ManyToOne,
6
  OneToMany
7
} from 'typeorm';
8
import { InvoiceUnits, Project } from '../Project/Project.entity';
9
import { User } from '../HumanResource/User/User.entity';
10
import { InvoiceItem } from './InvoiceItem.entity';
11
import { Quote } from './Quote.entity';
12
13
export enum InvoiceStatus {
14
  DRAFT = 'draft',
15
  SENT = 'sent',
16
  PAYED = 'payed',
17
  CANCELED = 'canceled'
18
}
19
20
@Entity()
21
export class Invoice {
22
  @PrimaryGeneratedColumn('uuid')
23
  private id: string;
24
25
  @Column('enum', {enum: InvoiceStatus, nullable: false})
26
  private status: InvoiceStatus;
27
28
  @Column('enum', {enum: InvoiceUnits, nullable: false})
29
  private unit: InvoiceUnits;
30
31
  @Column({type: 'varchar', nullable: false, unique: true})
32
  private invoiceId: string;
33
34
  @Column({type: 'timestamp', default: () => 'CURRENT_TIMESTAMP'})
35
  private createdAt: Date;
36
37
  @Column({type: 'timestamp'})
38
  private expiryDate: string;
39
40
  @ManyToOne(type => User, {nullable: false})
41
  private owner: User;
42
43
  @ManyToOne(type => Quote, {nullable: true})
44
  private quote: Quote;
45
46
  @ManyToOne(type => Project, {nullable: false})
47
  private project: Project;
48
49
  @OneToMany(
50
    type => InvoiceItem,
51
    invoiceItem => invoiceItem.invoice
52
  )
53
  items: InvoiceItem[];
54
55
  constructor(
56
    invoiceId: string,
57
    status: InvoiceStatus,
58
    expiryDate: string,
59
    unit: InvoiceUnits,
60
    owner: User,
61
    project: Project
62
  ) {
63
    this.invoiceId = invoiceId;
64
    this.status = status;
65
    this.expiryDate = expiryDate;
66
    this.unit = unit;
67
    this.owner = owner;
68
    this.project = project;
69
  }
70
71
  public getId(): string {
72
    return this.id;
73
  }
74
75
  public getInvoiceId(): string {
76
    return this.invoiceId;
77
  }
78
79
  public getExpiryDate(): string {
80
    return this.expiryDate;
81
  }
82
83
  public getStatus(): InvoiceStatus {
84
    return this.status;
85
  }
86
87
  public getUnit(): InvoiceUnits {
88
    return this.unit;
89
  }
90
91
  public getCreatedAt(): Date {
92
    return this.createdAt;
93
  }
94
95
  public getProject(): Project {
96
    return this.project;
97
  }
98
99
  public getOwner(): User {
100
    return this.owner;
101
  }
102
103
  public getQuote(): Quote | undefined {
104
    return this.quote;
105
  }
106
}
107